﻿@{
    ViewBag.Title = "编辑数据源配置";
    Layout = "~/Views/Shared/_Main.cshtml";
}@section Head{}
<script type="text/javascript">
    var parent;
    $(function () {
        parent = window.dialogArguments;
        $("#leftTable").empty();
        $("#rightTable").empty();
        $("#leftTable").append("<option value=''>-请选择表-</option>");
        $("#rightTable").append("<option value=''>-请选择表-</option>");
        for (var i = 0; i < parent.retData.length; i++) {
            $("#leftTable").append("<option value='" + parent.retData[i].ViewName + "'>" + parent.retData[i].DisplayName + "</option>");
            $("#rightTable").append("<option value='" + parent.retData[i].ViewName + "'>" + parent.retData[i].DisplayName + "</option>");
        }
    });
    function change(v, d) {
        $("#" + d).empty();
        $("#" + d).append("<option value=''>-选择表字段-</option>");
        $.post("/ODSConfig/SyncTableColumns?tableName=" + v + '&dbName=' + encodeURI($.getUrlParam("dbName")), function (result) {
            for (var i = 0; i < result.length; i++) {
                $("#" + d).append("<option>" + result[i] + "</option>");
            }
        });
    }
    function save() {
        if ($("#leftTable").val() == "") {
            alert("请选择左表名！");
            return;
        }
        if ($("#rightTable").val() == "") {
            alert("请选择右表名！");
            return;
        }
        if ($("#leftColumns").val() == "") {
            alert("请选择左表字段！");
            return;
        }
        if ($("#rightColumns").val() == "") {
            alert("请选择右表字段！");
            return;
        }
        if (($("#leftTable").val() + $("#leftColumns").val()) == ($("#rightTable").val() + $("#rightColumns").val())) {
            alert("不能添加相同字段的整合条件！");
            return;
        }
        var arr_ret = {
            LeftTableName: $("#leftTable").find("option:selected").text(),
            LeftViewName: $("#leftTable").val(),
            LeftColumnsName: $("#leftColumns").val(),
            Operator: "=",
            RightTableName: $("#rightTable").find("option:selected").text(),
            RightViewName: $("#rightTable").val(),
            RightColumnsName: $("#rightColumns").val(),
            GUID: parent.retDataOn.length
        };
        returnParent(arr_ret);
        return false;
    }
</script>
<div style="margin: 5px;">
    <table class="listTitle">
        <tr>
            <td width="15">
                <img src="/images/edit.png" />
            </td>
            <td width="300">
                编辑整合条件
            </td>
            <td align="right">
                <input type="button" class="button" value="确定" onclick="save();" />
            </td>
        </tr>
    </table>
    <table class="searchArea" width="100%">
        <tbody>
            <tr>
                <td height="130" valign="top" style="line-height: 25px;">
                    左表名：<select style="width: 250px" id="leftTable" onchange="change(this.value,'leftColumns')">
                    </select>
                    _
                    <select id="leftColumns" style="width: 150px">
                    </select>
                    <br>
                    操作符：=<br />
                    右表名：<select style="width: 250px" id="rightTable" onchange="change(this.value,'rightColumns')">
                    </select>
                    _
                    <select id="rightColumns" style="width: 150px">
                    </select>
                </td>
            </tr>
        </tbody>
    </table>
</div>
